//
//  WmcCloudAllPhotoCollectionHeaderView.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/30.
//

import UIKit

class WmcCloudAllPhotoCollectionHeaderView: UICollectionReusableView {
    // Lifecycle

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.makeUI()
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // Internal

    func bindModel(_ model: WmcMediaPhotoGroupModel) {
        var today: String = ""
        if let date = WmcDateManager.shared.networkDate.value {
            today = date.yp.string(.ymd_cn)
        }
        if today == model.date {
            dateLabel.text = "今天"
        } else {
            dateLabel.text = model.date
        }

        countLabel.text = "/\(model.list.count)张照片"
    }

    // Private

    private lazy var dateLabel: UILabel = {
        let label = UILabel()
        label.textColor = .wmc_grayH2_323233
        label.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
        return label
    }()

    private lazy var countLabel: UILabel = {
        let label = UILabel()
        label.textColor = .wmc_grayH5_606066
        label.font = UIFont.systemFont(ofSize: 13)
        return label
    }()

    private func makeUI() {
        self.backgroundColor = .wmc_white_FFFFFF

        addSubview(dateLabel)
        addSubview(countLabel)

        dateLabel.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.centerY.equalToSuperview()
        }

        countLabel.snp.makeConstraints { make in
            make.bottom.equalTo(dateLabel.snp.bottom).offset(-1)
            make.left.equalTo(dateLabel.snp.right)
        }
    }
}


extension WmcCloudAllPhotoCollectionHeaderView {
    
    /// 扩展 新model 方法，不该原有逻辑，修改
    
    func configure(model: WmcTeamMediaPhotoGroupModel) -> Void {
        var today: String = ""
        if let date = WmcDateManager.shared.networkDate.value {
            today = date.yp.string(.ymd_cn)
        }
        if today == model.date {
            dateLabel.text = "今天"
        } else {
            dateLabel.text = model.date
        }

        countLabel.text = "/\(model.list.count)张照片"
    }
}
